#ifndef     SHEETSPRITE_2018
#define     SHEETSPRITE_2018


#include    <map>
#include    <vector>
#include    <functional>


#include    "../concept/flexible.h"
#include    "../ui/uicommon/drawable.h"
#include    "../physical/movable/movablenode.h"
#include    "../picture/spritesheetrender.h"



class SheetSprite:
public Drawable,
public Flexible
{
public:
    SheetSprite();
    virtual ~SheetSprite();

public:
    static const Vec2D  DefaultVelocity;
    static const Vec2D  ZeroVelocity;
    enum ACTION{NOPIC = 0,IDLE,JUMP,ATTACK,JUMPATTACK,WALK,RUN,DEAD};
private:
	MovableNode* m_node;
	bool m_towardRight;
	ACTION m_action;
	ACTION m_lastAction;
	Vec2D m_velocity;
	std::map<ACTION,SpriteSheetPicture*> m_pictures;
	SpriteSheetRender* m_render;
	unsigned int m_showCount;
    std::vector<std::function<void(void)>> m_instruction;

public:
    #define PERSONAL_DEFAULT_RESOURCE_PATH  "resources/knight/"
    void loadResource(ACTION action,const char* name,const char* resourcePath = PERSONAL_DEFAULT_RESOURCE_PATH);

    void setAction(ACTION action);
    ACTION getAction()const{return m_action;}
    bool getToward()const{return m_towardRight;}
    void setToward(bool towardRight){m_towardRight = towardRight;}
    const Vec2D& getVelocity()const{return m_velocity;}
    void setVelocity(const Vec2D& velocity){m_velocity = velocity;}

public:
    virtual void update(TimeSeconds time)override;
    virtual void render()override;
};


#endif // SHEETSPRITE_2018
